package com.ews.onlineexchange.util;

import java.util.Calendar;

import com.ews.onlineexchange.model.assess.PeriodType;

public class PeriodUtils {
	
	public static Integer getPeriodYear( PeriodType periodType ) {
		Calendar cal = Calendar.getInstance();
		cal.add( Calendar.DAY_OF_MONTH, 5 );
		
		if ( periodType.equals( PeriodType.Year ) ) { 
			return cal.get( Calendar.YEAR ) - 1;
		} else if ( periodType.equals( PeriodType.Season ) ) {
			return cal.get( Calendar.MONTH ) / 3 == 0 ? cal.get( Calendar.YEAR ) - 1 : cal.get( Calendar.YEAR );
		} else if ( periodType.equals( PeriodType.Month ) ) {
			return cal.get( Calendar.MONTH ) == 0 ? cal.get( Calendar.YEAR ) - 1 : cal.get( Calendar.YEAR );
		}
		
		return null;
	}
	
	public static Integer getPeriodSn( PeriodType periodType ) {
		Calendar cal = Calendar.getInstance();
		cal.add( Calendar.DAY_OF_MONTH, 5 );
		
		if ( periodType.equals( PeriodType.Year ) ) { 
			return null;
		} else if ( periodType.equals( PeriodType.Season ) ) {
			return cal.get( Calendar.MONTH ) / 3 == 0 ? 4 : cal.get( Calendar.MONTH ) / 3;
		} else if ( periodType.equals( PeriodType.Month ) ) {
			return cal.get( Calendar.MONTH ) == 0 ? 12 : cal.get( Calendar.MONTH );
		}
		
		return null;
	}
	
}
